<?php

namespace app\common\behavior;

use think\facade\Config;

class MyQueueFailedLogger
{

    const should_run_hook_callback = false;

    public function logAllFailedQueues(&$jobObject){
        ly(array('da'=>$jobObject,'func'=>'MyQueueFailedLogger-logAllFailedQueues'));
        $failedJobLog = [
            'jobHandlerClassName'   => $jobObject->getName(), // 'application\index\job\Hello'
            'queueName' => $jobObject->getQueue(),			   // 'helloJobQueue'
            'jobData'   => $jobObject->getRawBody()['data'],  // '{'a': 1 }'
            'attempts'  => $jobObject->attempts(),            // 3
        ];
        var_export(json_encode($failedJobLog,true));

        // $jobObject->release();     //重发任务
        //$jobObject->delete();         //删除任务
        //$jobObject->failed();	  //通知消费者类任务执行失败
        return self::should_run_hook_callback;
    }

    /**
     * @title 失败回调通知方法
     * @description 失败回调通知方法
     * @author Admin ldy
     * @param name:jobobject  type:string require:1 default:1 desc:\think\queue\Job   //任务对象，保存了该任务的执行情况和业务数据
     * @return bool:是否返回回调成功通知//是否需要删除任务并触发其failed() 方法
     * @throws \HttpException
     * @throws \HttpResponseException
     * @time 2018/9/25  9:29
     */
    public function queueFailed(\think\queue\Job $jobObject){
//        ly(array('da'=>serialize($jobObject),'func'=>'MyQueueFailedLogger-queueFailed'));
        $failedJobLog = [
            'jobHandlerClassName'   => $jobObject->getName(), // 'application\index\job\Hello'
            'queueName' => $jobObject->getQueue(),			   // 'helloJobQueue'
            'jobData'   => $jobObject->getData(),  // '{'a': 1 }'
            'attempts'  => $jobObject->attempts(),            // 3
        ];
        $failedJobLog['queueFailed']='失败回调通知！！';
        ly($failedJobLog,'queueFailed-'.time());

        // $jobObject->release();     //重发任务
        //$jobObject->delete();         //删除任务
//        $jobObject->failed();	  //通知消费者类任务执行失败

        return self::should_run_hook_callback;
    }


}
